<template>
    <div>
        <span>主席
            <span>{{chairman.creditorName}}</span>
        </span><br>
        <hr size=8 style="COLOR: #ffd306;border-style:outset;width:100%;color:#CCC">

        <span>成员</span>
        <div v-for="member in memberList">
            <span>
                <span>{{member.creditorName}}</span>
            </span><br>
            <br>
            <hr size=8 style="COLOR: #ffd306;border-style:outset;width:100%;color:#CCC">
        </div>
        <!--<span>管理人推荐名单:</span>
        <ul v-for="(commend) in candidateMembers" class="name-list" style="width: 100%">
            <li style="text-align: left;display: inline" v-for="(people) in commend">{{people.name}}</li>
        </ul>-->
        <!--<hr size=8 style="COLOR: #ffd306;border-style:outset;width:100%;color:#CCC">
        <span >我的选举:
            <br/>{{nameList}}</span>
        <el-select v-model="chosenElect" filterable multiple :placeholder="placeholder">
            <el-option
                v-for="item in allList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
        </el-select>
        <div v-if="canVote === 0">
            <el-button class="committee-button" type="info" disabled>您没有选举权限</el-button>
        </div>
        <div v-else="canVote === 0">
            <el-button class="committee-button" type="primary" @click.native="confirm" v-if="showButton">确  定
            </el-button>
            <el-button class="committee-button" type="primary" @click.native="confirm" v-else="showButton">重新投票
            </el-button>
        </div>-->
    </div>
</template>

<script>
    import util from 'assets/js/util.js'

    export default {
        data() {
            return {
                // nameList: [],
                chairman: {},
                memberList: [],
                showButton: false,
                /*allList: [],
                chosenElect: [],
                canVote: 0,
                placeholder: '您没有选举权限',
                candidateMembers: [],*/
            }

        },
        methods: {
            /*confirm: function () {
                let polledCreditorIds = '';
                this.chosenElect.forEach(_id => polledCreditorIds += ',' + _id);
                polledCreditorIds = polledCreditorIds.substring(1, polledCreditorIds.length);

                const _self = this;
                util.ajax({
                    url: '/' + this.caseId + '/' + +this.creditorId + `/committeeInfo/recommend`,
                    params: {polledCreditorIds:polledCreditorIds},
                    success: function (data) {
                        _self.$message({
                            message: '选举成功!',
                            center: true
                        });
                        _self.showButton = false;
                    },
                });
            }*/
            roleType: function (type) {
                let typeText = '';
                switch (type) {
                    case 1:
                        typeText = '委员会成员';
                        break;
                    case 2:
                        typeText = '委员会主席';
                        break;
                    default:
                        break
                }
                return typeText
            }
        },
        mounted() {
            const _self = this;

            util.ajax({
                url: `/case/committee`,
                success: function (data) {
                    /*_self.creditorName = data.data.creditorName;
                    _self.role = _self.roleType(data.data.role);
                    _self.creditorId = data.data.creditorId;*/

                    data.data.forEach(people => {
                        if (people.role === 1) {
                            _self.memberList.push(people);
                        } else {
                            _self.chairman = people;
                        }
                    });
                }
            });


            /* const _self = this;
             util.ajax({
                 url: '/' + this.caseId + '/' + +this.creditorId + `/committeeInfo/electingInfo`,
                 success: function (data) {
                     _self.chinaMan = data.chinaMan;
                     _self.canVote = data.canVote !== 0;
                     _self.selectState = data.electedList.length === 0;
                     let childCommendList = [];
                     let commendSize = data.commendList.length;

                     for (let i = 0; i < commendSize; i++) {
                         if (i % 3 === 0)
                             childCommendList = [];
                         childCommendList.push({
                             id: data.commendList[i].id,
                             name: data.commendList[i].name
                         });
                         if (i % 3 === 2)
                             _self.commendList.push(childCommendList);
                     }
                     if (commendSize % 3 !== 0)
                         _self.commendList.push(childCommendList);

                     if (!_self.canVote) {
                         return;
                     }
                     if (_self.selectState) {
                         _self.placeholder = '请选择';
                         _self.showButton = true;
                     } else {
                         data.electedList.forEach(_elect => _self.chosenElect.push(_elect.id));
                         _self.showButton = false;
                     }
                     data.allList.forEach(_elect => _self.allList.push({
                         id: _elect.id,
                         name: _elect.name
                     }));
                     data.electedList.forEach(_elect => _self.nameList.push(_elect.name))
                 },
             });*/
        }
    }
</script>

<style scoped>
    div {
        font-size: 17px;
        margin: 10px 10px;
        display: block;
        line-height: 30px;
    }

    .committee-button {
        width: 100%;
        margin-top: 5%;
    }

    .name-list {
        list-style: none;
        padding-left: 0;
        line-height: 30px;
    }

    li {
        margin: 0 5%;
    }
</style>
